package com.servlet.servlet01;

import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;

/**
 * @author wzm
 * @create 2023-06-20 10:27
 */
//2.定义一个类实现servlet接口
//3.添加Servlet访问的路径
@WebServlet("/demo1")
public class ServletDemo01 implements Servlet {
    private ServletConfig config;
    //1.生命周期1-调用构造函数创建对象
    public ServletDemo01() {
        System.out.println("构造方法执行了，对象创建了");
    }

     //2.生命周期2-初始化Servlet
    @Override
    public void init(ServletConfig config) throws ServletException {
        System.out.println("2.初始化操作");
        this.config=config;
    }

    //获取ServletConfig对象
    @Override
    public ServletConfig getServletConfig() {
        return this.config;
    }

    //Servet功能的方法  生命周期3-Servlet提供服务
    @Override
    public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
        System.out.println("Hello,Servlet");
        System.out.println("servlet提供服务");
    }

    //获取Servlet信息
    @Override
    public String getServletInfo() {
        return "";
    }

    //生命周期4 销毁
    @Override
    public void destroy() {
        System.out.println("servlet销毁了");

    }
}
